<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

//home
Route::group(['domain' => config('app.website.HOME_DOMAIN')], function () {
    Route::get('/', function () {
        return redirect()->route('buz.auth.login');
    })->name('web.home');

});


Route::group(['domain' => config('app.website.GATEWAY_DOMAIN'), 'namespace' => 'Gateway'], function ($router) {

    $router->group(['prefix' => 'recharge'], function ($router) {
        $router->post('pay', 'RechargeGatewayController@pay')->name('gateway.recharge.pay');
        $router->any('query', 'RechargeGatewayController@queryOrder')->name('gateway.recharge.query');
        $router->any('callback/{identify}', 'RechargeGatewayController@callback')->name('gateway.recharge.callback');
        $router->any('return/{identify}/{orderno?}', 'RechargeGatewayController@returnHref')->name('gateway.recharge.return');
        $router->group(['prefix' => 'checkout', 'middleware' => ['checkout-pay']], function ($router) {
//            $router->any('/', 'RechargeGatewayController@checkout')->name('gateway.recharge.checkout');
            $router->post('/qrcode', 'CheckoutController@qrCode')->name('gateway.recharge.checkout.qrcode');
            $router->post('/bank', 'CheckoutController@bankHref')->name('gateway.recharge.checkout.bank');
            $router->post('/wap', 'CheckoutController@wap')->name('gateway.recharge.checkout.wap');
            $router->post('/sdk', 'CheckoutController@sdk')->name('gateway.recharge.checkout.sdk');
        });

        $router->get('/qrcode/{plat_no}', 'QrcodeShowController@show')->name('gateway.recharge.qrcode.show');


        $router->get('orderIsValidate', 'RechargeGatewayController@orderIsValidate')->name('gateway.recharge.checkValidate');
        $router->get('success', 'RechargeGatewayController@paySuccess')->name('gateway.recharge.success');
        $router->get('error', 'RechargeGatewayController@pageError')->name('gateway.recharge.error');
        $router->get('expired', function () {
            return view('gateway.recharge.expired');
        })->name('gateway.recharge.expired');

    });

});

//buz
Route::group([
    'domain' => config('app.website.BUZ_DOMAIN'),
    'namespace' => 'Buz',
    'middleware' => ['web']
], function ($router) {
    Route::get('login', function () {
        return view('buz.auth.login');
    })->name('buz.auth.login');
    Route::get('register_one', function () {
        return view('buz.auth.register.register_one');
    })->name('buz.register_one');
    Route::get('register_two', 'AuthController@doRegister')->name('buz.doregister');
    Route::get('register_email', 'AuthController@registerEmail')->name('buz.register_email');

    Route::get('register_three', function () {
        return view('buz.auth.register.register_three');
    })->name('buz.register_three');
    Route::get('forgetpwd', function () {
        return view('buz.auth.forget.forgetpwd');
    });
    Route::get('forgetpwd/passValidate', function () {
        return view('buz.auth.forget.passValidate');
    });
    Route::get('pwdUpdate', 'AuthController@passwordReset')->name('buz.passwordreset');
    Route::get('modifySuccess', function () {
        return view('buz.auth.forget.success');
    });
    Route::get('ie', function () {
        return view('buz.ie');
    });

    $router->group(['middleware' => ['web-auth']], function ($router) {
        //完善信息
        $router->any('auth/protocol', 'CompeteInfoController@getProtocol')->name('buz.auth.protocol');
        $router->get('auth/base', function () {
            return view('buz.information.prefectInfoBasic');
        })->name('buz.auth.base');
        $router->get('auth/remit', function () {
            return view('buz.information.prefectInfoSettlemet');
        })->name('buz.auth.remit');

        $router->group(['middleware' => 'web-info-complete'], function ($router) {
            $router->get('index', function () {
                return view('buz.index');
            });

            //应用充值记录
            $router->get('app/{id}/orders', function ($id) {
                return view('buz.app.payment', compact('id'));
            });
            //应用信息
            $router->get('app/{id}', function ($id) {
                return view('buz.app.info', ['id' => $id]);
            });
            //技术对接
            $router->get('app/{id}/docking', function ($id) {
                return view('buz.app.docking', ['id' => $id]);
            });
            //开通通道
            $router->get('member/paychanle', function () {
                return view('buz.app.paychanle');
            });


            //基本信息
            $router->get('member/info', function () {
                return view('buz.member.mindex');
            });
            //结算信息
            $router->get('member/remit', function () {
                return view('buz.member.msettlementIndex');
            });
            $router->get('member/remit/create', function () {
                return view('buz.member.msettlement_create');
            });
            $router->get('member/remit/{id}', function ($id) {
                return view('buz.member.msettlement', ['id' => $id]);
            })->where('id', '[0-9]+');
            //
//    $router->get('member/channel', function () {
//        return view('buz.member.mchannel');
//    });
            //密码管理
            $router->get('member/pwd', function () {
                return view('buz.member.mpassword');
            });
            //隐私数据
//            $router->get('member/privacy', function () {
//                return view('buz.member.mprivacy');
//            });
            $router->get('member/privacy', 'AuthController@privacy');
            //技术协议
            $router->get('member/agreement', function () {
                return view('buz.member.magreement');
            });

            //代付
            $router->get('remit/topay', function () {
                return view('buz.remit.topay');
            });
            //代付文件下载
            $router->get('remit/topay/file', function() {
//                $url = \Illuminate\Support\Facades\Storage::disk('files')->url('batchToPay.xls');
                $path = public_path('uploads/files') .'/batchToPay.xls';
                return response()->download($path, 'batchToPay.xls');
            })->name('buz.remit.batchFile');


            //代付记录
            $router->get('remit/topayList', function () {
                return view('buz.remit.topayList');
            });
            //提现
            $router->get('remit/withdraw', 'RemitController@withdraw');
            //提现记录
            $router->get('remit/withdrawList', function () {
                return view('buz.remit.withdrawList');
            });

            $router->get('files/api', function () {
                $path = public_path('uploads/files') .'/api.docx';
                return response()->download($path, '商户接入文档.docx');
            })->name('buz.files.api');

            $router->get('files/demo', function () {
                $path = public_path('uploads/files') .'/PHPDemo.rar';
                return response()->download($path, 'PHPDemo.rar');
            })->name('buz.files.demo');

            $router->get('/finance/bills', function () {
                return view('buz.remit.financeBill');
            });

            $router->group(['prefix' => 'statistic'], function ($router) {
                 $router->get('payments', function () {
                     return view('buz.statistic.payments');
                 });

//                 $router->group(['middleware' => 'auth-type:proxy'], function ($router) {
                 $router->get('suborders', function () {
                     return view('buz.statistic.suborders');
                 });
                 $router->get('substatistic', function () {
                     return view('buz.statistic.substastics');
                 });
                $router->get('submchinfo', function () {
                    return view('buz.statistic.submchInfo');
                });

//                 });
            });
        });


    });

});



Route::group(['namespace' => 'Gateway\Page'], function ($r) {
    $r->get('recharge/pay','RechargeController@index');
    $r->get('recharge/query',function () {
        return view('gateway.recharge.query');
    });
    $r->post('recharge/pay', 'RechargeController@pay');
    $r->post('recharge/query', 'RechargeController@query');
    $r->any('recharge/callback', 'RechargeController@callback')->name('page.callback');
});
